package com.coolingme.deep;


import java.util.ArrayList;

/**
 * 深克隆测试
 *
 * @author wangyue
 * @date 2020/9/30 9:41
 */
public class Test {

    public static void main(String[] args) {
        ConcretePrototype prototype = new ConcretePrototype();
        prototype.setName("Joey");
        prototype.setAge(58);

        ArrayList<String> hobbies = new ArrayList<>();
        hobbies.add("抽烟");
        hobbies.add("喝酒");
        hobbies.add("烫头");
        prototype.setHobbies(hobbies);

        System.out.println("prototype" + prototype);
        System.out.println("-------------------------");

        ConcretePrototype clone = prototype.clone();
        clone.getHobbies().add("说相声");
        System.out.println("prototype" + prototype);
        System.out.println("clone" + clone);

        // false
        System.out.println("prototype == clone:" + (prototype == clone));
        // false
        System.out.println("prototype.getHobbies() == clone.getHobbies():" + (prototype.getHobbies() == clone.getHobbies()));
        // false
        System.out.println("prototype.getName() == clone.getName():" + (prototype.getName() == clone.getName()));
    }

}
